import reqwest from 'reqwest'

import * as Api from '../../api/Api'

export const REQUEST_CHANNELS = 'REQUEST_CHANNELS'
export const RECEIVE_CHANNELS = 'RECEIVE_CHANNELS'

export function fetchChannels() {
	return (dispatch, getSate) => {
		dispatch({
			type: 'REQUEST_CHANNELS'
		})
		reqwest({
			url: Api.getChannels,
			method: 'post',
			data: {
				version_id: '1.1.0',
				longitude: '0',
				latitude: '0'
			},
			success: function(data) {
				dispatch({
					type: 'RECEIVE_CHANNELS',
					channels: JSON.parse(data).databody
				})
			}
		})
	}
}